import java.util.Arrays;

public class zuoye3_4 {
    public static void main(String[] args) {
        int[] nums={2,7,11,15};
        int target = 9;
        int[] result = add(nums,target);
        System.out.println(Arrays.toString(result));
    }
    public static int[] add(int[] arr2,int key){
        for (int i = 0; i < arr2.length; i++) {
            for (int j = i+1; j < arr2.length; j++) {
                if(arr2[i]+arr2[j] == key){
                    return new int[]{i,j};
                }
            }
        }
        return new int[]{};
    }
    public static void main4(String[] args) {
        int[] arr = {100,300,23,12,25,33,32,11,21};
        bubbling(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void bubbling(int[] num){
        for (int i = 0; i < num.length-1; i++) {
            for (int j = 0; j < num.length-1-i; j++) {
                if(num[j]>num[j+1]){
                    int temp=num[j];
                    num[j]=num[j+1];
                    num[j+1]=temp;
                }
            }
        }
    }
    public static void main3(String[] args) {
        int[] arr3={1,2,3,4,5,6,7,8,9};
        int ret = search(arr3,4);
        if(ret == -1){
            System.out.println("未找到");
        }
        else{
            System.out.println(ret);
        }

    }
    public static int search(int[] arr3,int key){
        int left = 0;
        int right = arr3.length - 1;
        while(left<=right){
            int mid = left+(right-left)/2;
            if(arr3[mid] > key){
                right = mid-1;
            }
            else if(arr3[mid] < key){
                left = mid+1;
            }
            else{
                return mid;
            }
        }
        return -1;
    }
    public static void main2(String[] args) {
        int[] arr2={1,2,3,4,5,6};
        int[] result = swap(arr2);
        System.out.println(Arrays.toString(result));
    }
    public static int[] swap(int[] arr2){
        int left=0;
        int right= arr2.length-1;
        while(left<right){
            while(left<right&&arr2[left]%2!=0){
                left++;
            }
            while(left<right&&arr2[right]%2==0){
                right--;
            }
            if(left<right){
                int temp=arr2[left];
                arr2[left]=arr2[right];
                arr2[right]=temp;
            }
        }
        return arr2;
    }
    public static void main1(String[] args) {
        int[] arr={1,2,3};
        transform(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]+" ");
        }
    }
    public static void transform(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i]=array[i]*2;
        }
    }
}
